import { createRouter, createWebHistory } from 'vue-router'

// 导入组件
import LoginVue from '@/views/login.vue'
import LayoutVue from '@/views/Layout.vue';
import FirstVue from '@/views/components/First.vue';
import SecondVue from '@/views/components/Second.vue';
import ShowVue from '@/components/Show.vue';
import ThreeVue from '@/views/components/Three.vue';
import FourVue from '@/views/components/Four.vue';

//定义路由关系
const routes = [
    { path: '/login', component: LoginVue },
    {
        path: '/', component: LayoutVue, redirect: '/user/first',
        children: [
            { path: '/user/first', component: FirstVue },
            { path: '/user/second', component: SecondVue },
            { path: '/user/three', component: ThreeVue },
            { path: '/user/four', component: FourVue }
        ]
    },
    { path: '/user/show/:id', component: ShowVue }
]

// 创建路由器
const router = createRouter({
    history: createWebHistory(),
    routes: routes,
    scrollBehavior(to, from, savedPosition) {
        // 始终滚动到顶部
        return { top: 0 };
    }
})

// 导出路由
export default router